<?php

namespace app\api\controller\gcw;

use app\admin\model\Gcw;
use app\common\model\Category;

/**
 * 次要广场舞接口
 */
class Secgcw extends Gcws
{

    public $control_version = '0.0.0';

    // Banner数据
    public function get_banner_list($v)
    {
        if ($v == $this->control_version) {
            $this->result('banner', array($this->fake_list[0], $this->fake_list[1], $this->fake_list[2]));
        }
        parent::get_banner_list(1);
    }

    // 随机视频列表
    public function get_ramdom_list($v)
    {
        if ($v == $this->control_version) {
            $this->result('normal', $this->fake_list);
        }
        parent::get_ramdom_list(1);
    }

    // 广场舞数据接口
    public function get_gcw_by_type($type, $v, $page = 1)
    {
        // 审核版本控制
        if ($v == $this->control_version) {
            $this->result('gcw', $this->fake_list);
        }

        // 判断广场舞小程序类型
        switch ($type) {
            case 'ssjqgcw':
                $category_id1 = '16';
                $category_id2 = '17';
                break;
            case 'ttylgcw':
                $category_id1 = '18';
                $category_id2 = '19';
                break;
            case 'jjgcwkt':
                $category_id1 = '20';
                $category_id2 = '21';
                break;
            default:
                $category_id1 = '14';
                $category_id2 = '15';
                break;
        }

        $list1 = Gcw::where('category_id', $category_id1)->limit(($page - 1) * 3, 3)->order('id', 'desc')->select();
        $list2 = Gcw::where('category_id', $category_id2)->limit(($page - 1) * 3, 3)->order('id', 'desc')->select();

        $list = array_merge($list1, $list2);

        // 格式化数据
        foreach ($list as $item) {
            $item->updatetime = date('m月d日', $item->updatetime);
            $item->duration = $this->secToTime($item->duration);
            $item->category_id = Category::get($item->category_id);
        }

        $this->result('ok', $list);
    }

    // 获取广场舞视频链接
    public function get_gcw($v, $id)
    {
        if ($v == $this->control_version) {
            $video = $this->fake_list[$id - 1];

            $this->result('video', array(
                'id' => $id,
                'title' => $video['title'],
                'cover' => $video['cover'],
                'category' => $video['category_id'],
                'updatetime' => $video['updatetime'],
                'content' => $video['content']
            ));
        }
        parent::get_gcw(1, $id);
    }

    // 获取某个分类下的所有视频
    public function get_gcw_list($v, $id, $page = 1)
    {
        if ($v == $this->control_version) {
            $gcw_list = array();

            foreach ($this->fake_list as $item) {
                if ($item['category_id']['id'] == $id) {
                    array_push($gcw_list, $item);
                }
            }

            $this->result('gcw', $gcw_list);
        }
        parent::get_gcw_list(1, $id, $page);
    }

}
